<?php defined('SYSPATH') or die('No direct access allowed.');

//version 1.1

class html extends html_Core {
	
	/**
	 * Creates a new menu item
	 * 
	 * @param   string         URL or URI string
	 * @param   string         language string to look for
	 * @param   boolean        menu item is selected
	 * @param   array          menu item has a submenu
	 * @return string
	 */
	public static function menu_li($uri, $lang_string, $selected=FALSE, $sub_array=array())
	{
		$li = '	<li'.($selected ? ' class="selected"' : '').'>'.self::anchor($uri, Kohana::lang($lang_string))."\n";
		
		if ( ! empty($sub_array))
		{
			$li .= '		<span class="hassub">&nbsp;</span>'."\n";
			$li .= ' 		<ul class="sub">'."\n";
			foreach ($sub_array as $uri=>$lang_string) $li .= '			<li>'.self::anchor($uri, Kohana::lang($lang_string))."</li>\n";
			$li .= " 		</ul>\n";
		}
		$li .= " 	</li>\n";
		return $li;
	}
	
	/**
	 * Shortcut for a simple anchor image
	 * 
	 * @param   string         URL or URI string
	 * @param   string         image source, or an array of image attributes
	 * @param   string|array   image alt attribute, or an array of attributes
	 * @param   array          HTML anchor attributes
	 * @param   string         non-default protocol, eg: https
	 * @param   boolean        include the index_page in the link
	 * @return string
	 */
	public static function img_anchor($uri, $src, $alt=NULL, $anchor_attributes = NULL, $protocol = NULL, $index = FALSE)
	{
		if ($alt && (empty($anchor_attributes) || empty($anchor_attributes['title']))) 
			$anchor_attributes['title'] = $alt;
		return html::anchor($uri, html::image($src, $alt, $index), $anchor_attributes, $protocol);
	}

	/**
	 * Generates hidden form fields.
	 * You can pass a simple key/value string or an associative array with multiple values.
	 *
	 * @param   string|array  input name (string) or key/value pairs (array)
	 * @param   string        input value, if using an input name
	 * @return  string
	 */
	public static function hidden($data, $value = '')
	{
		if ( ! is_array($data))
		{
			$data = array
			(
				$data => $value
			);
		}

		$input = '';
		foreach ($data as $name => $value)
		{
			$attr = array
			(
				'type'  => 'hidden',
				'name'  => $name,
				'id'  => $name,
				'value' => $value
			);

			$input .= form::input($attr)."\n";
		}

		return $input;
	}
}